﻿using Mengsk.ProxyDelivery.Domain;
using Mengsk.ProxyDelivery.Print.Domain;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;

namespace Mengsk.ProxyDelivery.Print.Domain.PrintDataFormatters
{
    class PrintDataFormatterOther_Image : PrintDataFormatter
    {
        public override PrintTemplateItemTypes AcceptType
        {
            get { return PrintTemplateItemTypes.OTHER_IMAGE; }
        }

        public override object Format(PrintTemplate template, PrintTemplateItem item,Order order)
        {
            if (template.AttachImages.ContainsKey(item.Format) == false)
            {
                throw new Exception("图片不存在");
            }

            var bi = new BitmapImage();
            bi.BeginInit();
            bi.StreamSource = new MemoryStream(template.AttachImages[item.Format], false);
            bi.EndInit();
            return bi;
        }
    }
}
